package gui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.*;

import bot.City;
import bot.PageGenerator;
import bot.Util;

public class PopulationSidePanelButton extends JButton{

	/**
	 * Default Serialization
	 */
	private static final long serialVersionUID = 1L;
	private JTextField url;
	private JTextField date;
	
	private PageGenerator page;
	
	public PopulationSidePanelButton(JTextField textCity, JTextField textDate){
		super("Population Side Panel");
		url = textCity;
		date = textDate;
		page = new PageGenerator();
		
//		addActionListener(new ActionListener(){
//			@Override
//			public void actionPerformed(ActionEvent arg) {
//				try{
//					//make sure input is valid
//					if (Util.parseName(url.getText()).equals("")){
//						throw new IllegalArgumentException();
//					}
//					City choosen = new City(BotGui.demo, BotGui.area, Util.parseName(url.getText()));
//					//put the population info in the paste buffer
//					Util.setPasteBuffer(page.getPopSidePanel(choosen, date.getText(), true));
//				}
//				catch (IllegalArgumentException e){
//					e.printStackTrace();
//					JOptionPane.showMessageDialog(null, "Invaild city name");
//				}
//			}
//		});
		addMouseListener(new MouseListener(){
			@Override
			public void mouseClicked(MouseEvent arg0) {
				boolean referenceType = false;
				if (arg0.getButton() == MouseEvent.BUTTON1){
					referenceType = true;
				}
				
				try{
					//make sure input is valid
					if (url.getText().equals("")){
						throw new IllegalArgumentException();
					}
					City choosen = new City(url.getText(), BotGui.data);
					//put the population info in the paste buffer
					Util.setPasteBuffer(page.getPopSidePanel(choosen, date.getText(), referenceType));
				}
				catch (IllegalArgumentException e){
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "Invaild city name");
				}
			}
			@Override
			public void mouseEntered(MouseEvent arg0){}
			@Override
			public void mouseExited(MouseEvent arg0){}
			@Override
			public void mousePressed(MouseEvent arg0){}
			@Override
			public void mouseReleased(MouseEvent arg0){}
		});
	}
}
